package com.huangyan.service;

import com.huangyan.dao.UserDao;
import com.huangyan.dao.LoginLogDao;
import com.huangyan.domin.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by huangyan on 2017/6/21.
 */
@Service("userService")
public class UserService {

    @Autowired
    UserDao userDao;
    @Autowired
    LoginLogDao loginLogDao;

    Map<String,String> tokenMap=new HashMap<String, String>();
    public boolean hasMatchUser(String username,String password)
    {
        tokenMap.put("username",username);
        tokenMap.put("password",password);
        int count=userDao.getMatchCount(tokenMap);
        if(count>0)
            return true;
        else
            return false;
    }

    public User findUserByUserName(String username)
    {
        return userDao.findUserByUserName(username);
    }

    @Transactional
    public void loginSuccess(User user)
    {
        loginLogDao.insertLoginLog(user);
    }
}
